package hd.util.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import hd.util.ColorUtil;

/**
 * 标题栏的阴影
 * <p/>
 * Created by haidy on 14/12/21.
 */
public class TitleBarShadowView extends View {

    private int shadowColor = Color.argb(31, 0, 0, 0);
    private Paint paint;
    private LinearGradient lg;

    public TitleBarShadowView(Context context) {
        this(context, null);
    }

    public TitleBarShadowView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TitleBarShadowView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (lg == null) {
            lg = new LinearGradient(getWidth() / 2, 0, getWidth() / 2, getHeight(), shadowColor, ColorUtil.alphaColor(0, shadowColor), Shader.TileMode.MIRROR);
            paint = new Paint();
            paint.setShader(lg);
        }
        canvas.drawPaint(paint);
    }
}
